package com.ams.studio.xml;


import org.dom4j.Node;

import java.util.ArrayList;
import java.util.List;

/**

 * Created by zhongyl on 2016-06-29.

 */
public class XmlNodeContext {
    private Node node;
    private XmlHelper helper;

    XmlNodeContext(XmlHelper helper, Node node) {
        this.helper = helper;
        this.node = node;
    }

    public XmlHelper getHelper() {
        return helper;
    }

    Node getNode() {
        return node;
    }

    public XmlLoopContext toLoopContext() {
        List<Node> nodes = new ArrayList<Node>();
        nodes.add(node);
        return new XmlLoopContext(helper, nodes);
    }

    public boolean isValid() {
        return helper != null && node != null;
    }

    public String getNodeValue() {
        return node.getText();
    }
}
